package com.twu.biblioteca;


import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: twer
 * Date: 10/3/13
 * Time: 12:39 AM
 * To change this template use File | Settings | File Templates.
 */
public class Library {
    private String _welcomeMessage = "Welcome to the Bangalore Public Library";
    private String _moviesFilePath;
    private Menu _menu = new Menu();
    private Book _book = new Book();
    private ReadMovieFile _moviesFile = new ReadMovieFile();

    public void setMoviesFilePath(String moviesFilePath) {
        _moviesFilePath = moviesFilePath;
    }

    public void printWelcomeMessage() {
        System.out.println(_welcomeMessage);
    }

    public void printMenu() {
        ArrayList<String> menuList = _menu.getItems();
        for(String menu : menuList){
            System.out.println( menuList.indexOf(menu) + 1 + ". " + menu);
        }
    }

    public Menu getMenu() {
        return _menu;
    }

    public Book getBooks() {
        return _book;
    }

//    public boolean selectedOptionValidation(String selectedOption, ArrayList<String> selectedType) {
//        if(selectedOption == null){
//            return false;
//        }
//        else{
//            int optionNum = Integer.parseInt(selectedOption);
//            return optionNum>=1 && optionNum<=selectedType.size();
//        }
//    }

    public void menuDirected(String menuSelected) {
        int menu = Integer.parseInt(menuSelected);
//        System.out.println("Please enter 0 to back to the menu list.");
        switch (menu) {
            case 1:
                System.out.println("Please talk to a Librarian. Thank you.");
                break;
            case 2:
                ArrayList<String> books = _book.getItems();
                for(String book : books){
                    System.out.println(books.indexOf(book)+1 + ". " +book);
                }
                break;
            case 3:
                _moviesFile.setFilePath(_moviesFilePath);
                ArrayList<Movie> movies = _moviesFile.readFile();
                System.out.println("Movie Year Director Rating");
                for(Movie movie: movies){
                    System.out.println(movie.getName() + " " + movie.getYear() + " " + movie.getDirector() + " " + movie.getRating());
                }
                break;
            default:
                System.out.println("This item has no descriptions!");
                break;
        }
    }
//
//    public String inputOption(User user, Menu menu) {
//        boolean isValid = false;
//        String selectedOption = null;
//        while(!isValid){
//            selectedOption = user.getUserInput(menu.getInputPrompt());
//            isValid = selectedOptionValidation(selectedOption, getMenu());
//            if(isValid) break;
//            System.out.println(menu.getErrorPrompt());
//        }
//        return selectedOption;
//    }

}

